package com.facebookapp.framework;

public class Facebook {
	public static native void initFaceBook(String appId, String domain)/*-{
		window.fbAsyncInit = function() {
			FB.init({
				appId : appId, // App ID from the app dashboard
				channelUrl : 'http://' + domain + '/channel.html',
				status : true,
				xfbml : true
			});
		};

		(function(d, s, id) {
			var js, fjs = d.getElementsByTagName(s)[0];
			if (d.getElementById(id)) {
				return;
			}
			js = d.createElement(s);
			js.id = id;
			js.src = "http://connect.facebook.net/en_US/all.js";
			fjs.parentNode.insertBefore(js, fjs);
		}(document, 'script', 'facebook-jssdk'));
	}-*/;

	public static native String getLoginStatus()/*-{
		FB.getLoginStatus(function(response) {
			if (response.status === 'connected') {
				return response;
			} else if (response.status === 'not_authorized') {
				return null;
			} else {
				return 'login';
			}
		});
	}-*/;

	public static native String login(FacebookEventListener listener, String scope)/*-{
		FB.login(
			function(response) {
				if (response.authResponse) {
					listener.@com.facebookapp.framework.FacebookEventListener::onEvent(Ljava/lang/String;)(response);
				} else {
					console
							.log('User cancelled login or did not fully authorize.');
				}
			}, {
				scope : scope
		});
	}-*/;

	public static native String logout(FacebookEventListener listener, String scope)/*-{
		FB.logout(function(response) {
					listener.@com.facebookapp.framework.FacebookEventListener::onEvent(Ljava/lang/String;)(response);
		});
	}-*/;
}
